﻿namespace l1cs_cl.client
{
    public class Data
    {
        private static Data _instance = new Data();

        private int _nowCount = 0;         // 所持キャラクター数
        private int _maxCount = 0;         // 所持できる最大キャラクター数
        private Character[] _characters;   // キャラクター情報配列
        private Character _activeCharacter;  // アクティブなキャラクター情報

        // getter,setter
        public Character[] characters { get; set; }
        public static Data Instance
        {
            get { return _instance; }
        }

        public int nowCount
        {
            get { return _nowCount; }
            set { _nowCount = value; }
        }

        public int maxCount
        {
            get { return _maxCount; }
            set
            {
                this._maxCount = value;
                this._characters = new Character[this._maxCount];
            }
        }

        public Character activeCharacter { get; set; }
        
        private Data() { }

        public int addCharacter( Character character )
        {
            int count = 0;
            for ( int i = 0; i < _maxCount; i++ )
            {
                if ( _characters[i] == null )
                {
                    _characters[i] = character;
                    count++;
                    break;
                }
                else
                {
                    count++;
                }
            }
            return count;
        }

        public int delCharacter( int num )
        {
            if ( _characters.Length <= num )
            {
                return 0;
            }
            else
            {
                _characters[num] = null;
                return 1;
            }
        }

        public Character getCharacter( int num )
        {
            if ( _characters.Length <= num )
            {
                // 範囲外の場合
                return null;
            }
            else
            {
                return _characters[num];
            }
        }

        //public void addPacket( PlayerBasePacket pbp )
        //{
        //    lock ( packetList )
        //    {
        //        packetList.Add( pbp );
        //    }
        //}

        //public PlayerBasePacket[] getPacketList()
        //{
        //    lock ( packetList )
        //    {
        //        return packetList.ToArray();
        //    }
        //}
    }
}
